<?php
/**
 * Created By PhpStorm
 * Author: patrick wu
 * Date: 2020/10/8
 * Time: 9:23
 */
namespace App\Http\Controllers\Api;

use App\Service\Api\CategoryService;
use Illuminate\Http\Request;
use App\Constant\ErrorConstant;

class CategoryController extends BaseController
{
    protected $service;

    public function __construct(Request $request, CategoryService $service)
    {
        parent::__construct($request);
        $this->service  =   $service;
    }

    /**
     * 分页模板数据
     * @return \Illuminate\Http\JsonResponse
     */
    public function showCategory()
    {
        [$flag, $result]    =   $this->service->categoryShow();
        if ($flag) {
            return $this->successResponse($result);
        } else {
            return $this->errorResponse(ErrorConstant::API_CAT_DATA_ERROR, $result);
        }
    }

    /**
     * 分页数据
     * @return \Illuminate\Http\JsonResponse
     */
    public function dataCategory()
    {
        [$flag, $result]    =   $this->service->categoryData();
        if ($flag) {
            return $this->successResponse($result);
        } else {
            return $this->errorResponse(ErrorConstant::API_CAT_DATA_ERROR, $result);
        }
    }
}
